package com.xuetang9.t9.hotel.mapper;

import com.xuetang9.t9.hotel.beans.RoomState;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Pang
 */
@Repository
public interface IRoomStateMapper {

    /**
     * 添加状态
     * @param state
     * @return
     */
    @Insert("INSERT INTO g_roomstate VALUES(#{stateId},#{stateName},#{stateComm})")
    int insert(RoomState state);


    /**
     * 删除状态
     * @param id
     * @return
     */
    @Delete("DELETE FROM g_roomstate WHERE state_id=#{id}")
    int delete(Integer id);


    /**
     * 修改状态
     * @param state
     * @return
     */
    @Update("UPDATE g_roomstate SET state_name=#{stateName},state_comm=#{stateComm} WHERE state_id=#{stateId}")
    int update(RoomState state);


    /**
     * 根据Id查找
     * @param id
     * @return
     */
    @Select("SELECT * FROM g_roomstate WHERE state_id = #{id}")
    RoomState selectById(int id);

    /**
     * 查找全部的房间状态(附加)
     * @return
     */
    @Select("SELECT * FROM g_roomstate")
    @Results(value = {
            @Result(id = true,column = "state_id",property = "stateId"),
            @Result(column = "state_id",property = "stateId",many = @Many(select = "com.xuetang9.t9.hotel.mapper.IRoomInfoMapper.selectByStateId",fetchType = FetchType.LAZY))
    })
    List<RoomState> selectByAll();

    /**
     * 查找全部的房间状态
     * @return
     */
    @Select("SELECT * FROM g_roomstate")
    List<RoomState> selectByStateAll();
}
